package com.template.config;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInterceptor;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author MLTong
 */
@Configuration
public class HelperPageConfig {


    @Resource
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @Bean
    public PageHelper pageHelper(){
        return new PageHelper();
    }

    @PostConstruct
    public void addInterceptor() {
        PageInterceptor pageInterceptor = new PageInterceptor();
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(pageInterceptor);
        }
    }
}
